Here's a script I ended up putting
together for my roomate.. He wanted to be able to have a row of
spike-trap-type effects that would trigger off one after another,
continuously, and damage anyone unfortunate enough to get in their way.
The code is currently still a little messy, especially the actual
effect/damage code (since I just wrapped my code around his). If anyone
can improve on it, please do!
The way I used this was to create a row of invisible objects, named
something like "MyTrapTest", "MyTrapTest0", "MyTrapTest1",
"MyTrapTest2", etc. Then I set this script to the OnHeartBeat of the
first object:
NWScript:
void main()
{
if(GetLocalInt(OBJECT_SELF, "already_triggered") != 1)
{
string sMyBaseName = GetTag(OBJECT_SELF);
SetLocalInt(OBJECT_SELF, "CurrentTrap", 0);
int nCount = 0;
while(GetIsObjectValid( GetObjectByTag( sMyBaseName + IntToString(nCount))))
{
nCount++;
}
SetLocalInt(OBJECT_SELF, "MaxTraps", nCount - 1);
SetLocalInt(OBJECT_SELF, "already_triggered", 1);
SignalEvent(OBJECT_SELF, EventUserDefined(0));
}
}
And this script to the OnUserDefined of the first object:
NWScript:
void main()
{
string sMyBaseName = GetTag(OBJECT_SELF);
int nCurrent = GetLocalInt(OBJECT_SELF, "CurrentTrap");
int nMax = GetLocalInt(OBJECT_SELF, "MaxTraps");
object oTarget = GetFirstObjectInShape(SHAPE_CUBE, 0.5, GetLocation( GetObjectByTag(sMyBaseName + IntToString(nCurrent))), FALSE, OBJECT_TYPE_CREATURE);
effect eDam = EffectDamage(d6(2), DAMAGE_TYPE_PIERCING);
effect eVis = EffectVisualEffect(253);
ApplyEffectAtLocation( DURATION_TYPE_INSTANT, eVis, GetLocation( GetObjectByTag(sMyBaseName + IntToString(nCurrent))));
if(GetIsPC(oTarget))
{
int nAC = GetAC(oTarget);
int nRoll = d20() + 11;
if (nRoll > 0)
{
ApplyEffectToObject( DURATION_TYPE_INSTANT, eDam, oTarget);
}
}
nCurrent++;
if(nCurrent > nMax) { nCurrent = 0; }
SetLocalInt(OBJECT_SELF, "CurrentTrap", nCurrent);
DelayCommand(2.0, SignalEvent( GetObjectByTag(sMyBaseName), EventUserDefined(0)));
}
I think any object with both an OnHeartBeat and an OnUserDefined script
could be used as locations for the traps, but I haven't tested with
anything other than an invisible object yet.
[Edit]
Ye gads, just after posting this, I realized that it would only affect
player characters, not npcs and such. Gonna have to figure out a way to
fix that... my roomate's code originally used GetNearestCreature, but I
changed it to the current form because it wasn't finding a target
correctly when I started using invisible objects in place of trigger
spots.
[/Edit]
_________________
Morituri Nolumus Mori!
|